import { _decorator, Component, Enum, error, EventTouch, Node, Sprite, SpriteFrame, v3, Vec3 } from 'cc';
import { GameUtil } from './GameUtil';
import { PARTGRADE } from './GameConstant';
import { BoxController } from './BoxController';
import { BoxManager } from './BoxManager';
const { ccclass, property } = _decorator;

@ccclass('WeaponPart')
export class WeaponPart extends Component {

    @property({ type: Enum(PARTGRADE) })
    PartType: PARTGRADE;

    IsMax: boolean = false;
    private _box: Node = null;//压在下面的BoxCollider

    upgrade() {
        const nextPart = GameUtil.getAdjacentEnumCirculation(PARTGRADE, this.PartType, true, false);
        BoxManager.Instance.upgradePart(nextPart, this._box);
        this.node.destroy();
    }

    add(target: Node) {
        this._box = target;
        if (!this._box.getComponent(BoxController)) console.error(this._box.name);

        this._box.getComponent(BoxController).add(this.node);
    }

    remove() {
        this._box.getComponent(BoxController).remove();
        this._box = null;
    }


}


